;
(function() {
	module.exports = {
		prefix: "/bus/space",
		get: {
			"/list": function() {
				var bus = role.getBus(this);
				this.body = ResponObj("json", bus.getSpaceList());
			},
			"/list/by_type": function() {
				var bus = role.getBus(this);
				var query = this.request.query;
				if (!query.type) {
					throwCusError("参数错误");
				}
				this.body = ResponObj("json", bus.getSpaceListByType(query.type));
			},
			"/list/by_use_state": function() {
				var bus = role.getBus(this);
				var query = this.request.query;
				if (!query.use_state) {
					throwCusError("参数错误");
				}
				this.body = ResponObj("json", bus.getSpaceListByUseState(query.use_state));
			},
			"/list/:bus_id": function() {
				var bus = BusCon.get(this.params.bus_id);
				if (!bus) {
					throwCusError("找不到指定商家")
				}
				this.body = ResponObj("json", bus.getSpaceList());
			},
			"/list/by_type/:bus_id": function() {
				var bus = BusCon.get(this.params.bus_id);
				if (!bus) {
					throwCusError("找不到指定商家")
				}
				var query = this.request.query;
				if (!query.type) {
					throwCusError("参数错误");
				}
				this.body = ResponObj("json", bus.getSpaceListByType(query.type));
			},
			"/list/by_use_state/:bus_id": function() {
				var bus = BusCon.get(this.params.bus_id);
				if (!bus) {
					throwCusError("找不到指定商家")
				}
				var query = this.request.query;
				if (!query.use_state) {
					throwCusError("参数错误");
				}
				this.body = ResponObj("json", bus.getSpaceListByUseState(query.use_state));
			},
		},
		post: {
			"/add_space": function() {
				var bus = role.getBus(this);
				var body = this.request.body;
				this.body = ResponObj("json", bus.addSpace(body));
			},
		},
		put: {
			"/update_space/:space_id": function() {
				var bus = role.getBus(this);
				var body = this.request.body;
				var space_id = this.params.space_id;
				this.body = ResponObj("json", bus.updateSpace(space_id, body));
			}
		},
		"delete": {
			"/remove_space/:space_id": function() {
				var bus = role.getBus(this);
				var body = this.request.body;
				var space_id = this.params.space_id;
				bus.removeSpace(space_id, body)
				this.body = ResponObj("string", "删除成功");
			}
		}
	}
	var role = require("./role");
	var BusCon = require("../../core/bus/_con");
	var UserCon = require("../../core/user/_con");
	var GoodsCon = require("../../core/goods/_con");
	var AchCon = require("../../core/ach/_con");
	var db = require("../../core/db/index");
	var config = require("../../core/_include/config");
	var ResponObj = require("../_include/responObj");
}());